package com.liuyk.commonlib.adapter;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;

import java.util.ArrayList;

/**
 * 容器adapter
 * <p>
 * Created by liuyk on 2019/3/13.
 */
public abstract class BaseFragmentPagerAdapter extends FragmentPagerAdapter {
    /**
     * FragmentStatePagerAdapter 适合大量页面，不断重建和销毁
     * FragmentPagerAdapter 适合少量页面，常驻内存
     */

    private ArrayList<Fragment> mFragments;

    public BaseFragmentPagerAdapter(FragmentManager fm) {
        super(fm);
    }

    public void setFragments(ArrayList<Fragment> fragments) {
        this.mFragments = fragments;
    }

    @Override
    public Fragment getItem(int position) {
        return mFragments != null && !mFragments.isEmpty() ? mFragments.get(position) : null;
    }

    @Override
    public int getCount() {
        return mFragments != null ? mFragments.size() : 0;
    }

    @Override
    public int getItemPosition(Object object) {
        return POSITION_NONE;
    }
}
